using GameBasic;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

namespace VCity
{
    public class FerrisWheel : MonoBehaviour
    {
        public GameObject capsuleShipPrefab;
        public float degreePerSecond = 0.2f; // degree per second
        public float radius = 100;
        public int count = 32;

        public Transform wheel;

        Transform[] ships;

        // Start is called before the first frame update
        void Start()
        {
            ships = new Transform[count];
            float degree = 360f / count;
            Vector3 vector = Vector3.up * radius;
            for (int i = 0; i < count; i++)
            {
                var obj = Instantiate(capsuleShipPrefab, transform);
                ships[i] = obj.transform;
                obj.transform.localPosition = wheel.transform.localPosition + Quaternion.Euler(0, 0, degree * i) * vector;
            }
        }

        // Update is called once per frame
        void Update()
        {
            var rot = wheel.transform.localRotation;
            rot *= Quaternion.Euler(0, 0, Time.deltaTime * degreePerSecond);
            wheel.transform.localRotation = rot;

            float degree = 360f / count;
            Vector3 vector = Vector3.up * radius;
            for (int i = 0; i < count; i++)
            {
                var tr = ships[i];
                tr.localPosition = wheel.transform.localPosition + rot * Quaternion.Euler(0, 0, degree * i) * vector;
            }
        }
    }
}